package com.example.hans.navigationbyviewpageandradiobutton;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;


//recycleView的适配器
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ViewHolder> {

    List<Contact> contactList;


    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView head_portrait;
        TextView info;
        View chartView;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            chartView = itemView;
            head_portrait = itemView.findViewById(R.id.head_portrait);
            info = itemView.findViewById(R.id.tv_info);
        }
    }

    public ContactAdapter(List<Contact> contacts) {
        this.contactList = contacts;
    }




    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()
        ).inflate(R.layout.contact_item,viewGroup,false);
        ViewHolder holder = new ViewHolder(view);
        holder.head_portrait.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


            }
        });
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, int position) {
        Contact contact = contactList.get(position);
        viewHolder.info.setText(contact.getName()+"\n"+contact.getPhone());
        viewHolder.head_portrait.setImageResource(R.drawable.ic_launcher_background);
    }

    @Override
    public int getItemCount() {
        return contactList.size();
    }
}
